package org.accp.controller;

import org.accp.dao.PermissionDao;
import org.accp.pojo.Permission;
import org.accp.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
@RequestMapping("/permission")
@CrossOrigin("*")
public class PermissionController {
    @Autowired
    private PermissionDao permissionDao;
    @RequestMapping("/all")
    @ResponseBody
    public List<Permission> searchAll() throws Exception{
        return permissionDao.getAll();
    }

    @RequestMapping("/all002")
    @ResponseBody
    public List<Permission> searchAllParent() throws Exception{
        return permissionDao.getParentPerms();
    }

    @ResponseBody
    @RequestMapping("/rolePers/{roleid}")
    public List<Integer> searchRolePers(@PathVariable Integer roleid) throws Exception {
        return permissionDao.getPerIdByRoleId(roleid);
    }
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseResult delete(int perid) throws Exception{
        permissionDao.delete(perid);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/add")
    @ResponseBody
    public ResponseResult add(Permission permission) throws Exception{
        permissionDao.add(permission);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/update")
    @ResponseBody
    public ResponseResult update(Permission permission ) throws Exception{
        permissionDao.update(permission);
        return ResponseResult.createSuccessResult();
    }
}
